<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row class="inputSearch">
        <el-col :span="8">
          <el-input placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table
        :data="orderList"
        stripe border
        style="width: 100%">
        <el-table-column type="index">
        </el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="180">
        </el-table-column>
        <el-table-column
          prop="pay_status"
          label="是否付款">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status==='0'">未支付</el-tag>
            <el-tag type="success" v-else>已支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货">
        </el-table-column>
        <el-table-column
          label="下单的时间">
          <template slot-scope="scope">
            {{ scope.row.create_time|dataFormat }}
          </template>
        </el-table-column>
        <el-table-column
          label="操作">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="light" content="修改订单地址" placement="bottom">
              <el-button type="primary" size="mimi" icon="el-icon-edit" @click="showBox"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="light" content="物流进度设置" placement="bottom">
              <el-button type="success" size="mimi" icon="el-icon-location"
                         @click="showProgressBox()"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 5, 10, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>

    </el-card>

    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="50%" @close="closeDialog">
      <el-form :model="addForm" :rules="addRules" ref="addRuleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="省市区/县" prop="address1">

          <el-cascader
            v-model="addForm.address1"
            :options="cityData"
            @change="handleChange"></el-cascader>

        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>

    <!--物流进度的对话框-->
    <el-dialog
      title="物流进度"
      :visible.sync="progressDialogVisible"
      width="50%">

      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in progressInfo"
          :key="index"
          :timestamp="item.time">
          {{ item.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'
import  progressInfo from './progressInfo'
export default {
  name: "Order",
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      total: 0,
      orderList: [],
      dialogVisible: false,
      addForm: {
        address1: [],
        address2: ''
      },
      addRules: {
        address1: [{required: true, message: '请输入选择省市区地址', trigger: 'blur'}],
        address2: [{required: true, message: '请输入详细地址', trigger: 'blur'}]
      },
      cityData: cityData,
      progressDialogVisible: false,
      progressInfo: progressInfo
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    async getOrderList() {
      const {data: res} = await this.$http.get('orders', {params: this.queryInfo})
      if (res.meta.status === 200) {
        console.log(res.data)
        this.orderList = res.data.goods
        this.total = res.data.total
      } else {
        this.$message.error(res.meta.msg)
      }
    },
    handleSizeChange(pageSize) {
      this.queryInfo.pagesize = pageSize
      console.log(this.queryInfo.pagesize)
      this.getOrderList()
    },
    handleCurrentChange(currPage) {
      this.queryInfo.pagenum = currPage
      console.log(this.queryInfo.pagenum)
      this.getOrderList()
    },
    showBox() {
      this.dialogVisible = true
      console.log(this.cityData)
    },
    handleChange() {

    },
    closeDialog() {
      this.$refs.addRuleForm.resetFields()
    },
    async showProgressBox(item) {
      this.progressDialogVisible = true
      // const {data: res} = await this.$http.get('/kuaidi/804909574412544580')
      // if (res.meta.status === 200) {
      //   this.$message.success(res.meta.message)
      //   this.progressInfo = res.data
      // } else {
      //   this.$message.error(res.meta.message)
      // }
      this.$message.success("获取物流信息成功！")
    }
  }

}
</script>

<style lang="less" scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item(1).css';
.inputSearch {
  margin-bottom: 20px;
}
</style>
